
#include <stddef.h>
#include "HT162X_Parts_Num.h"
#include "HT162X.h"
#include "HT162X_Pin.h"
#include "../MCU_Mold/MCU_AbstractTube.h"
#include "UI.h"


const uint8_t TempAct_seg1[8][2] = 
{
    {Cad_Com7,Cad_Pin_14}, //A
    {Cad_Com5,Cad_Pin_14}, //B
    {Cad_Com2,Cad_Pin_14}, //C
    {Cad_Com1,Cad_Pin_14}, //D
    {Cad_Com3,Cad_Pin_14}, //E
    {Cad_Com6,Cad_Pin_14}, //F
    {Cad_Com4,Cad_Pin_14}, //G
    {0,0}, //.
};
const uint8_t TempAct_seg2[8][2] = 
{
    {Cad_Com7,Cad_Pin_15}, //A
    {Cad_Com5,Cad_Pin_15}, //B
    {Cad_Com2,Cad_Pin_15}, //C
    {Cad_Com1,Cad_Pin_15}, //D
    {Cad_Com3,Cad_Pin_15}, //E
    {Cad_Com6,Cad_Pin_15}, //F
    {Cad_Com4,Cad_Pin_15}, //G
    {0,0}, //.
};
const uint8_t TempAct_seg3[8][2] = 
{
    {Cad_Com7,Cad_Pin_16}, //A
    {Cad_Com5,Cad_Pin_16}, //B
    {Cad_Com2,Cad_Pin_16}, //C
    {Cad_Com1,Cad_Pin_16}, //D
    {Cad_Com3,Cad_Pin_16}, //E
    {Cad_Com6,Cad_Pin_16}, //F
    {Cad_Com4,Cad_Pin_16}, //G
    {0,0}, //.
};
const uint8_t Timer_seg1[8][2] = 
{
    {Cad_Com7,Cad_Pin_7}, //A
    {Cad_Com5,Cad_Pin_7}, //B
    {Cad_Com2,Cad_Pin_7}, //C
    {Cad_Com1,Cad_Pin_7}, //D
    {Cad_Com3,Cad_Pin_7}, //E
    {Cad_Com6,Cad_Pin_7}, //F
    {Cad_Com4,Cad_Pin_7}, //G
    {0,0}, //.
};
const uint8_t Timer_seg2[8][2] = 
{
    {Cad_Com7,Cad_Pin_8}, //A
    {Cad_Com5,Cad_Pin_8}, //B
    {Cad_Com2,Cad_Pin_8}, //C
    {Cad_Com1,Cad_Pin_8}, //D
    {Cad_Com3,Cad_Pin_8}, //E
    {Cad_Com6,Cad_Pin_8}, //F
    {Cad_Com4,Cad_Pin_8}, //G
    {0,0}, //.
};
const uint8_t Timer_seg3[8][2] = 
{
    {Cad_Com7,Cad_Pin_9}, //A
    {Cad_Com5,Cad_Pin_9}, //B
    {Cad_Com2,Cad_Pin_9}, //C
    {Cad_Com1,Cad_Pin_9}, //D
    {Cad_Com3,Cad_Pin_9}, //E
    {Cad_Com6,Cad_Pin_9}, //F
    {Cad_Com4,Cad_Pin_9}, //G
    {0,0}, //.
};
const uint8_t Timer_seg4[8][2] = 
{
    {Cad_Com7,Cad_Pin_10}, //A
    {Cad_Com5,Cad_Pin_10}, //B
    {Cad_Com2,Cad_Pin_10}, //C
    {Cad_Com1,Cad_Pin_10}, //D
    {Cad_Com3,Cad_Pin_10}, //E
    {Cad_Com6,Cad_Pin_10}, //F
    {Cad_Com4,Cad_Pin_10}, //G
    {0,0}, //.
};
const uint8_t Timer_seg5[8][2] = 
{
    {Cad_Com7,Cad_Pin_11}, //A
    {Cad_Com5,Cad_Pin_11}, //B
    {Cad_Com2,Cad_Pin_11}, //C
    {Cad_Com1,Cad_Pin_11}, //D
    {Cad_Com3,Cad_Pin_11}, //E
    {Cad_Com6,Cad_Pin_11}, //F
    {Cad_Com4,Cad_Pin_11}, //G
    {0,0}, //.
};
const uint8_t PSet_seg1[8][2] = 
{
    {Cad_Com7,Cad_Pin_12}, //A
    {Cad_Com5,Cad_Pin_12}, //B
    {Cad_Com2,Cad_Pin_12}, //C
    {Cad_Com1,Cad_Pin_12}, //D
    {Cad_Com3,Cad_Pin_12}, //E
    {Cad_Com6,Cad_Pin_12}, //F
    {Cad_Com4,Cad_Pin_12}, //G
    {0,0}, //.
};
const uint8_t Probe1_seg1[8][2] = 
{
    {Cad_Com7,Cad_Pin_5}, //A
    {Cad_Com5,Cad_Pin_5}, //B
    {Cad_Com2,Cad_Pin_5}, //C
    {Cad_Com1,Cad_Pin_5}, //D
    {Cad_Com3,Cad_Pin_5}, //E
    {Cad_Com6,Cad_Pin_5}, //F
    {Cad_Com4,Cad_Pin_5}, //G
    {0,0}, //.
};
const uint8_t Probe1_seg2[8][2] = 
{
    {Cad_Com7,Cad_Pin_4}, //A
    {Cad_Com5,Cad_Pin_4}, //B
    {Cad_Com2,Cad_Pin_4}, //C
    {Cad_Com1,Cad_Pin_4}, //D
    {Cad_Com3,Cad_Pin_4}, //E
    {Cad_Com6,Cad_Pin_4}, //F
    {Cad_Com4,Cad_Pin_4}, //G
    {0,0}, //.
};
const uint8_t Probe1_seg3[8][2] = 
{
    {Cad_Com7,Cad_Pin_3}, //A
    {Cad_Com5,Cad_Pin_3}, //B
    {Cad_Com2,Cad_Pin_3}, //C
    {Cad_Com1,Cad_Pin_3}, //D
    {Cad_Com3,Cad_Pin_3}, //E
    {Cad_Com6,Cad_Pin_3}, //F
    {Cad_Com4,Cad_Pin_3}, //G
    {0,0}, //.
};
const uint8_t Probe2_seg1[8][2] = 
{
    {Cad_Com7,Cad_Pin_2}, //A
    {Cad_Com5,Cad_Pin_2}, //B
    {Cad_Com2,Cad_Pin_2}, //C
    {Cad_Com1,Cad_Pin_2}, //D
    {Cad_Com3,Cad_Pin_2}, //E
    {Cad_Com6,Cad_Pin_2}, //F
    {Cad_Com4,Cad_Pin_2}, //G
    {0,0}, //.
};
const uint8_t Probe2_seg2[8][2] = 
{
    {Cad_Com7,Cad_Pin_1}, //A
    {Cad_Com5,Cad_Pin_1}, //B
    {Cad_Com2,Cad_Pin_1}, //C
    {Cad_Com1,Cad_Pin_1}, //D
    {Cad_Com3,Cad_Pin_1}, //E
    {Cad_Com6,Cad_Pin_1}, //F
    {Cad_Com4,Cad_Pin_1}, //G
    {0,0}, //.
};
const uint8_t Probe2_seg3[8][2] = 
{
    {Cad_Com7,Cad_Pin_13}, //A
    {Cad_Com5,Cad_Pin_13}, //B
    {Cad_Com2,Cad_Pin_13}, //C
    {Cad_Com1,Cad_Pin_13}, //D
    {Cad_Com3,Cad_Pin_13}, //E
    {Cad_Com6,Cad_Pin_13}, //F
    {Cad_Com4,Cad_Pin_13}, //G
    {0,0}, //.
};


void Lcd_Number(uint8_t num,uint8_t (*array)[2])
{
    uint8_t i;
    Cad_Dat_S Cad_Dat;
    
    for (i = 0; i < 8; i++)
    {
        Cad_Dat.Cad_Com = array[i][0];
        Cad_Dat.Cad_Pin = array[i][1];
        if(num < Tube_Length)
        {
            Cad_Dat.Cad_Dis = (((Tube_Encoder[num] >> i) + Nixie_Num_Inverse) & 0x01);
            HT_RAM_Setting(Cad_Dat); 
        }
    }
}

void Lcd_Numbers(int32_t param,uint8_t (*array4)[2],uint8_t (*array3)[2],uint8_t (*array2)[2],uint8_t (*array1)[2])
{
    uint8_t temp;

    if((*array4) != NULL)
    {
        temp = (param / 1000) % 10;
        Lcd_Number(temp,array4);
    }
    if((*array3) != NULL)
    {
        temp = (param / 100) % 10;
        Lcd_Number(temp,array3);
    }
    if((*array2) != NULL)
    {
        temp = (param / 10) % 10;
        Lcd_Number(temp,array2);
    }
    if((*array1) != NULL)
    {
        temp = param % 10;
        Lcd_Number(temp,array1);
    }
}

void Lcd_NumShow(UI_Number_E t,int32_t param)
{
    if(t == UI_Timer_Hour)
    {
        param *= 100;
        Lcd_Numbers(param,Timer_seg2,Timer_seg3,NULL,NULL);
    }
    else if(t == UI_Timer_Minute) Lcd_Numbers(param,NULL,NULL,Timer_seg4,Timer_seg5);
    else if(t == UI_PSet)
    {
 //       Lcd_PSet(Char_ON);
        Lcd_Numbers(param,NULL,NULL,NULL,PSet_seg1);
    }

	if(t == UI_RTD)
	{
		if(UI_System.Grill_Unit == Unit_C)
		{
			param = F_Convert_C(param);
		}
		if(Temp_Param.oven_Err == Pt_Normal)
		{
            if(Prime_Enable == 0)
            {
                if(param < 0)
                {
                    param = -param; 
                    Lcd_Number(Tube_Encoder_Crossbar,TempAct_seg1);
                    Lcd_Number((param / 10) % 10,TempAct_seg2);
                    Lcd_Number(param % 10,TempAct_seg3);
                }
			    else Lcd_Numbers(param,NULL,TempAct_seg1,TempAct_seg2,TempAct_seg3);
            }
            else
            {
                Lcd_Number(Tube_Encoder_P,TempAct_seg1);
                Lcd_Number(Tube_Encoder_r,TempAct_seg2);
                Lcd_Number(Tube_Encoder_i,TempAct_seg3);
            }
		}
		else
		{
			Lcd_Number(Tube_Encoder_E_Char,TempAct_seg1);
			Lcd_Number(Tube_Encoder_r,TempAct_seg2);
            if(Temp_Param.oven_Err == Pt_Open) Lcd_Number(Tube_Encoder_O,TempAct_seg3);
            else if(Temp_Param.oven_Err == Pt_Short) Lcd_Number(Tube_Encoder_S,TempAct_seg3);
            else if(Temp_Param.oven_Err == Pt_HighTemp) Lcd_Number(Tube_Encoder_H,TempAct_seg3);
            else if(Temp_Param.oven_Err == Pt_LowTemp) Lcd_Number(Tube_Encoder_L,TempAct_seg3);
		}
	}
	else if(t == UI_RTDSettings)
	{
		if(UI_System.Grill_Unit == Unit_C)
		{
			param = F_Convert_C(param);
		}
        if(Temp_Param.oven_set == Temp_Set_Smoke)
        {
            Lcd_Cook(Char_OFF);
 //           Lcd_PSet(Char_ON);
            Lcd_Number(Tube_Encoder_Space,Timer_seg1);
			Lcd_Number(Tube_Encoder_Space,Timer_seg2);
			Lcd_Number(Tube_Encoder_Space,Timer_seg3);
            // Lcd_Numbers(UI_System.Pset - PSet_0,NULL,NULL,NULL,PSet_seg1);
        }
        else
        {
            Lcd_Cook(Char_ON);
            Lcd_PSet(Char_OFF);
            if(Temp_Param.oven_set >= 450)
            { //H1
                Lcd_Number(Tube_Encoder_Space,Timer_seg1);
                Lcd_Number(Tube_Encoder_H,Timer_seg2);
                Lcd_Number(1,Timer_seg3);
            }
            else Lcd_Numbers(param,NULL,Timer_seg1,Timer_seg2,Timer_seg3);
			Lcd_Number(Tube_Encoder_Space,PSet_seg1);
        }
        Lcd_Number(Tube_Encoder_Space,Timer_seg4);
        Lcd_Number(Tube_Encoder_Space,Timer_seg5);
	}
	else if(t == UI_ProbeA)
	{
		if(UI_System.Grill_Unit == Unit_C)
		{
			param = F_Convert_C(param);
		}
		if(Temp_Param.probe1_Err == Pt_Normal)
        {
            if(param < 0)
            {
                param = -param; 
                Lcd_Number(Tube_Encoder_Crossbar,Probe1_seg1);
                Lcd_Number((param / 10) % 10,Probe1_seg2);
                Lcd_Number(param % 10,Probe1_seg3);
            }
            else Lcd_Numbers(param,NULL,Probe1_seg1,Probe1_seg2,Probe1_seg3);
        }
		else
		{
			Lcd_Number(Tube_Encoder_n,Probe1_seg1);
			Lcd_Number(Tube_Encoder_o,Probe1_seg2);
			Lcd_Number(Tube_Encoder_P,Probe1_seg3);
		}
	}
	else if(t == UI_ProbeB)
	{
		if(UI_System.Grill_Unit == Unit_C)
		{
			param = F_Convert_C(param);
		}
		if(Temp_Param.probe2_Err == Pt_Normal)
        {
            if(param < 0)
            {
                param = -param; 
                Lcd_Number(Tube_Encoder_Crossbar,Probe2_seg1);
                Lcd_Number((param / 10) % 10,Probe2_seg2);
                Lcd_Number(param % 10,Probe2_seg3);
            }
            else Lcd_Numbers(param,NULL,Probe2_seg1,Probe2_seg2,Probe2_seg3);
        } 
		else
		{
			Lcd_Number(Tube_Encoder_n,Probe2_seg1);
			Lcd_Number(Tube_Encoder_o,Probe2_seg2);
			Lcd_Number(Tube_Encoder_P,Probe2_seg3);
		}
	}
    else if(UI_System.Timer1.Actual > 0)
    { //熄火状态
        if(t == UI_RTD)
        { //OFF
            Lcd_Number(0,TempAct_seg1);
            Lcd_Number(Tube_Encoder_F,TempAct_seg2);
            Lcd_Number(Tube_Encoder_F,TempAct_seg3);
        }
        // else if(t == UI_RTDSettings) Lcd_Numbers(LcdSeg_Shine_OFF,NULL,TempAct_seg1,TempAct_seg2,TempAct_seg3);
        // else if(t == UI_ProbeA) Lcd_Numbers(LcdSeg_Shine_OFF,NULL,Probe1_seg1,Probe1_seg2,Probe1_seg3);
        // else if(t == UI_ProbeB) Lcd_Numbers(LcdSeg_Shine_OFF,NULL,Probe2_seg1,Probe2_seg2,Probe2_seg3);
    }
    else
    { //关机状态(不断电源,只关闭屏幕)
        // if(t == UI_RTD) Lcd_Numbers(LcdSeg_Shine_OFF,NULL,TempAct_seg1,TempAct_seg2,TempAct_seg3);
        // Lcd_Numbers(LcdSeg_Shine_OFF,Timer_seg1,Timer_seg2,NULL,NULL);
        // Lcd_Numbers(LcdSeg_Shine_OFF,NULL,NULL,Timer_seg3,Timer_seg4);
        Lcd_Wifi(Char_OFF);
        Lcd_Backlight_OFF;
    }
}

void Lcd_NumShow_Shine(UI_Number_E t,uint32_t param)
{
	/*
    if(t == UI_System.State_Operation)
    {
    }
    Lcd_NumShow(t,param);
	*/
}
